package com.caigou.service.impl;

import com.caigou.bean.cms.entity.ChannelData;
import com.caigou.bean.cms.param.ArticlePublishChannelParam;
import com.caigou.mapper.cms.ChannelDataMapper;
import com.caigou.pojo.ArticleReleaseChannelList;
import com.caigou.pojo.ArticleReleaseList;
import com.caigou.pojo.ChannelDataMobile;
import com.caigou.service.ChannelDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("channelDataService")
@Slf4j
public class ChannelDataServiceImpl implements ChannelDataService {

    @Resource
    private ChannelDataMapper channelDataMapper;

    @Override
    public Integer loadArticleReleaseCount(String articleId) {
        return channelDataMapper.loadArticleReleaseCount(articleId);
    }

    @Override
    public List<ArticleReleaseList> loadArticleReleaseList(String articleId) {
        return channelDataMapper.loadArticleReleaseList(articleId);
    }

    @Override
    public void saveChannelData(Integer titleType, String articleId, String plateId, Integer articleType, Integer showIndex, Integer recommendStatus, Integer stickStatus, Integer lockStatus) {
        ChannelData channelData = new ChannelData();
        channelData.setTitleType(titleType);
        channelData.setArticleId(articleId);
        channelData.setPlateId(plateId);
        channelData.setDataType(articleType);
        channelData.setShowIndex(showIndex);
        channelData.setRecommendStatus(recommendStatus);
        channelData.setStickStatus(stickStatus);
        channelData.setLockStatus(lockStatus);
        channelDataMapper.saveChannelData(channelData);
    }

    @Override
    public int loadArticleReleaseStatus(String articleId, String plateId) {
        return channelDataMapper.loadArticleReleaseStatus(articleId,plateId);
    }

    @Override
    public ChannelData loadLastChannelData(String articleId) {
        return channelDataMapper.loadLastChannelData(articleId);
    }

    @Override
    public ChannelData loadArticleReleaseChannelData(String articleId, String plateId) {
        return channelDataMapper.loadArticleReleaseChannelData(articleId,plateId);
    }

    @Override
    public List<ChannelData> loadLastChannelAllData(String articleId) {
        return channelDataMapper.loadLastChannelAllData(articleId);
    }

    @Override
    public List<String> loadRssList() {
        return channelDataMapper.loadRssList();
    }

    @Override
    public List<ChannelDataMobile> loadChannelBannerDataMobileList(String plateId) {
        return channelDataMapper.loadChannelBannerDataMobileList(plateId);
    }

    @Override
    public List<ChannelDataMobile> loadChannelDataMobileList(String plateId) {
        return channelDataMapper.loadChannelDataMobileList(plateId);
    }

    @Override
    public List<ChannelDataMobile> loadChannelAllDataMobileList(String plateId) {
        return channelDataMapper.loadChannelAllDataMobileList(plateId);
    }

    @Override
    public List<ChannelDataMobile> loadChannelDataMoreMobileList(List<String> plateIdList) {
        List<String> list = new ArrayList<>();
        for (String info: plateIdList){
            String sql = "";
            if (info.length() == 3) {
                sql = "a.plate_id > "+info+"000000 AND a.plate_id < "+info+"999999";
            } else if (info.length() == 5){
                sql = "a.plate_id > "+info+"0000 AND a.plate_id < "+info+"9999";
            } else if (info.length() == 7){
                sql = "a.plate_id > "+info+"00 AND a.plate_id < "+info+"99";
            } else {
                sql = "a.plate_id = "+info;
            }
            list.add(sql);
        }
        return channelDataMapper.loadChannelDataMoreMobileList(list);
    }

    @Override
    public int deleteArticle(String articleId) {
        return channelDataMapper.deleteArticle(articleId);
    }

    @Override
    public List<ArticleReleaseChannelList> loadArticleReleaseChannelList(String articleId) {
        return channelDataMapper.loadArticleReleaseChannelList(articleId);
    }

    @Override
    public int loadChannelDataCount(String plateId) {
        return channelDataMapper.loadChannelDataCount(plateId);
    }

    @Override
    public int loadChannelDataLockCount(String plateId) {
        return channelDataMapper.loadChannelDataLockCount(plateId);
    }
}
